<h1>Listing books </h1>
<table width="100%">
  <tr>
  <% for column in Book.content_columns %>
    <% unless ['state','idx'].include?(column.name) -%>
       <th><%= column.human_name %></th>
    <% end -%>

  <% end %>
  <th>State</th>
  <th>Category</th>
  <th>Language</th>
  <th colspan='5'>Action</th>
  </tr>

<% for book in @books %>
  <tr>
  <% for column in Book.content_columns %>
    <% unless ['state','idx'].include?(column.name) -%>
       <td><%=h book.send(column.name) -%></td>
    <% end -%>
  <% end %>
    <td><%= link_to %Q{#{format_state(book.state)}}, {:action => 'list', :state => book.state} %></td>
    <td><%= link_to %Q{#{book.category.name}}, {:action => 'list', :category_id => book.category.id} %></td>
    <td><%= link_to %Q{#{book.language.name}}, {:action => 'list', :language_id => book.language.id} %></td>
    <td><%= link_to('Borrow',{:action => 'new', :controller => 'borrowings', :book_id => book.id}, :method => :post) if logged_in_admin? && book.state == Book::STATE_AVAILABLE %></td>
    <td><%= link_to('Show', :action => 'show', :id => book) %></td>
    <td><%= link_to('Edit', :action => 'edit', :id => book) if logged_in_admin?  %></td>
    <td><%= link_to('Destroy',{ :action => 'destroy', :id => book }, :confirm => 'Are you sure?', :method => :post) if logged_in_admin? %></td>
  </tr>
<% end %>
</table>

  <form action='/books/search' method='post'>    
    <input name="inx" type="text" />
    <input type='submit' value='Search' />
  </form>

<div class='news'>
  <%= link_to 'Previous page', { :page => @book_pages.current.previous } if @book_pages.current.previous %>
  <%= link_to 'Next page', { :page => @book_pages.current.next } if @book_pages.current.next %>
</div>

<% if logged_in_admin? %>
  <%= link_to 'New book', :action => 'new' %>
<% end %>
